/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.soa.service.busi.wx;

import com.lianzt.commondata.AbstractCommonData;
import com.lianzt.util.StringUtil;
import com.soa.controller.tccgl.WeixinController;
import com.soa.exception.GlobalException;
import com.soa.service.BaseService;
import com.soa.util.SystemUtil;
import com.soa.util.tccgl.WeixinUtil;
import javax.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

/**
 *  P90002
 *  保存收树信息
 * @author chang
 */
@Service
public class SaveSsxx extends BaseService{
    @Resource
    private WeixinUtil weixinUtil;
    private final Logger log = LoggerFactory.getLogger(SaveSsxx.class);

    @Override
    public String[] keys() {
        return null;
    }

    @Override
    public void execute(AbstractCommonData in, AbstractCommonData inhead, AbstractCommonData out, AbstractCommonData outhead) {
        AbstractCommonData session = getSession(in);
        String userid = session.getStringValue("userid");
        //获取照片id
        String pic = in.getStringValue("pic");
        if(StringUtil.notNull(pic)){
            //开始下载照片
            log.debug("=============开始下载照片:{}", pic + ".jpg");
            try {
                    this.weixinUtil.downFile("image", pic);
                } catch (Exception e) {
                    throw new GlobalException(9000202, e);
                }
            in.putStringValue("pic", pic);
        }
        String id = SystemUtil.getSerialNum();
        //insert into jz_ss(id,hmlx,dj,sl,hmsyr,zj,yfk,wfk,hmysgd,bz,shrq,lrr,lrsj,sffq,pic) values(:id[string],:hmlx[string],:dj[double],:sl[double],:hmsyr[string],:zj[double],:yfk[double],:wfk[double],:hmysgd[string],:bz[string],:shrq[date],:lrr[string],sysdate,:sffq[string],:pic[string])
        in.putStringValue("id", id);
        in.putStringValue("lrr", userid);
        String sffk = in.getStringValue("sffk");//是否付全款 0否 1是
        if("0".equals(sffk)){
            in.putStringValue("sffq", "0");
        }else{
            in.putStringValue("sffq", "1");
        }
        try {
            update("insert_jz_ss", in);
        } catch (Exception e) {
            log.debug("保存收树信息出现异常！", e);
            throw new GlobalException(9000201, e);
        }
    }
    
}
